!function(exports){
    function callobjfn(){
        var efn=function(){};
        var fnobj={
            cbk:efn,
            para:null,
            json:null,
            header:null,
            jsoncbk:null,
        }
        return {
            cbk:function(fn){fnobj.cbk=fn;return this},
            para:function(para){fnobj.para=para;return this},
            header:function(para){fnobj.header=para;return this},
            jsoncbk:function(fn){fnobj.jsoncbk=fn;return this},
            json:function(json){fnobj.json=json;return this},
            fnobj:fnobj
        }
    }
    function header(http,para){
        if(!para)return;
        for(var key in para){
            http.setRequestHeader(key,para[key]);
        }
    }
    function parafn(para){
        if(!para)return;
        var r=[];
        for(var key in para)r.push(key+"="+para[key])
        return r.join("&");
    }
    function get(url){
        var http=new XMLHttpRequest();
        var callobj=callobjfn();
        setTimeout(function(){//放到后面操作
			if(callobj.fnobj.para==null)void 0;
            else if(~url.indexOf("?"))url+="&"+parafn(callobj.fnobj.para);
            else url+="?"+parafn(callobj.fnobj.para);
            http.open("get",url);
            header(http,callobj.fnobj.header);
            http.onreadystatechange=function(){
                if(http.readyState!=4)return;
                if(http.status!=200){
                    callobj.fnobj.cbk(http.status);
                    if(callobj.fnobj.jsoncbk)callobj.fnobj.jsoncbk(http.status);
                    return;
                }
                callobj.fnobj.cbk(null,http.responseText);
                if(callobj.fnobj.jsoncbk)callobj.fnobj.jsoncbk(null,JSON.parse(http.responseText));
            }
            http.send(null);
        },20);
        return callobj;
    }
    function post(url){
        var http=new XMLHttpRequest();
        var callobj=callobjfn();
        setTimeout(function(){//放到后面操作
            http.open("post",url);
            header(http,callobj.fnobj.header);
            http.onreadystatechange=function(){
                if(http.readyState!=4)return;
                if(http.status!=200){
                    callobj.fnobj.cbk(http.status);
                    if(callobj.fnobj.jsoncbk)callobj.fnobj.jsoncbk(http.status);
                    return;
                }
                callobj.fnobj.cbk(null,http.responseText);
                if(callobj.fnobj.jsoncbk)callobj.fnobj.jsoncbk(null,JSON.parse(http.responseText));
            }
            var json=callobj.fnobj.json;
            if(!json){
                http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                http.send(parafn(callobj.fnobj.para));
            }else{
                http.setRequestHeader("Content-Type","text/json");
                http.send(JSON.stringify(json));
            }
        },20);
        return callobj;
    }
	exports.ajax={
		get:get,
		post:post
	}
}(this);